import axios from 'axios';
import {message} from 'antd';

console.log(process.env.NODE_ENV)
if (process.env.NODE_ENV === "development") {
    axios.defaults.baseURL = "http://127.0.0.1:8002/";
} else {
    axios.defaults.baseURL = "http://127.0.0.1:8002/";
}
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    return config;
}, function (error) {
    return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    console.log("响应拦截器", response)
    return response.data;
}, function (error) {
    if (error.status >= 400 && error.status < 500) {
        message.warning(error.response.data.Message)
    } else if (error.status >= 500) {
        message.error(error.response.data.Message)
    }
    console.log("响应拦截器错误", error)
    return null;
});
const http = {
    login: (data) => {
        return new Promise((resolve, reject) => {
            axios.post("login", data).then(res => {
                resolve(res);
            })
        })
    },
    register: (data) => {
        return new Promise((resolve, reject) => {
            axios.post("register", data).then(res => {
                resolve(res);
            })
        })
    }
}
export default http;